package com.chunyu.ask.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.chunyu.ask.bean.Article;
import com.chunyu.ask.service.ArticleService;
import com.chunyu.ask.util.PageUtils;
import com.chunyu.ask.util.RespMsg;

/**
 * 描        述：文章详细
 * 创建时间：2016-8-18
 * @author Jibaole
 */
@Controller
@RequestMapping("/article")
public class ArticleController extends BaseController{
	@Autowired
	private ArticleService articleService;
	
	 @RequestMapping("/getList/{pages}/{showNum}")
	public @ResponseBody
	RespMsg getList(@PathVariable int pages, @PathVariable int showNum) {
		RespMsg result = new RespMsg();
		Map<String, Object> paramMap = new HashMap<String, Object>();
		try {
			paramMap.put("firstResult", pages);
			paramMap.put("maxResult", showNum);
			List<Article> objList = articleService.getList(paramMap);
			result.resultObj = objList;
			result.status = true;
		} catch (Exception e) {
			result.status = false;
			result.msg="加载文章列表异常";
			e.printStackTrace();
		}
		return result;
	}
	 /**
	  * 文章详细内容
	  * @param id
	  * @return
	  */
	 
	 @RequestMapping("/page/{id}")
	public ModelAndView getById(@PathVariable int id) {
		ModelAndView view = new ModelAndView(PageUtils.ARTICLE_DETAIL);
		try {
			Article article = articleService.getById(id);
			view.addObject("article", article);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return view;
	}
	 
}
